package com.example.demo.service;

import javax.jms.JMSException;
import javax.jms.TextMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.example.demo.entity.SysUser;

/**
 * 接收消息的业务类
 * 
 * @author acer
 *
 */
@Service
public class MessageService {

	@Autowired
	EmailService emailService;
	 
	
	@JmsListener(destination = "good_msg")
	public void getGoodMessage(String message) throws JMSException {
		// TextMessage textMsg = (TextMessage) message;
		// System.out.println(textMsg.getJMSTimestamp());
		// System.out.println(textMsg.getText());
		System.out.println("接受到的消息:" + message);
	}

	@JmsListener(destination = "order_msg")
	public void getOrderMessage(String msg) {

	}

	@JmsListener(destination = "user_msg")
	public void getUserMessage(String msg) {
		SysUser user = JSON.parseObject(msg, SysUser.class);
		System.out.println("接受到的消息:"+msg);
		
		// 发邮件
		//
		
		
		
//		emailService.sendEmail("主题-附件邮件", user.getEmail(), "以下是附件!");
		
		emailService.sendEmailToTlp("主题-注册邮件", user.getEmail(), user.getUsername());
	}
}
